package com.zzyl.nursing.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.dto.PageQueryDto;
import com.zzyl.nursing.mapper.NursingProjectMapper;
import com.zzyl.nursing.service.MemberOrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: JBY
 * @since: 2025/08/21 20:17
 */
@Service
@Slf4j
public class MemberOrdersServiceImpl extends ServiceImpl<NursingProjectMapper, NursingProject> implements MemberOrdersService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 分页查询
     *
     * @param ordersPageQueryDto
     * @return TableDataInfo
     */
    @Override
    public TableDataInfo<NursingProject> pageQuery(PageQueryDto ordersPageQueryDto) {
        Page page = new Page<>(ordersPageQueryDto.getPageNum(), ordersPageQueryDto.getPageSize());
        this.lambdaQuery().like(StrUtil.isNotEmpty(ordersPageQueryDto.getName()), NursingProject::getName, ordersPageQueryDto.getName())
                .eq(ObjUtil.isNotNull(ordersPageQueryDto.getStatus()), NursingProject::getStatus, ordersPageQueryDto.getStatus())
                .page(page);
        List<NursingProject> list = BeanUtil.copyToList(page.getRecords(), NursingProject.class);
        TableDataInfo<NursingProject> tableDataInfo = new TableDataInfo<>();
        tableDataInfo.setRows(list);
        tableDataInfo.setTotal(page.getTotal());
        tableDataInfo.setCode(200);
        tableDataInfo.setMsg("查询成功");
        return tableDataInfo;
    }

    /**
     * 根据ID回显护理项目
     * @param id
     * @return NursingProject
     */
    @Override
    public NursingProject getById(Long id) {
        NursingProject byId = nursingProjectMapper.selectById(id);
        return byId;
    }
}
